package com.cosina.game.robodefence.eventlistener;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.cosina.game.robodefence.R;
import com.cosina.game.robodefence.RoboDefenceActivity;
import com.cosina.game.robodefence.core.BattleEngine;
import com.cosina.game.robodefence.dao.MapsDao;
import com.cosina.game.robodefence.model.GameStartConfig;
import com.cosina.game.robodefence.ui.view.ViewPort;

public class LevelPageEventListener {

	public static void doReg(final RoboDefenceActivity acty) {
		{
			final TextView selectLevel = (TextView)acty.findViewById(R.id.selectLevel);
			ImageView levelDown = (ImageView)acty.findViewById(R.id.levelDown);
			selectLevel.setText("Level " + GameStartConfig.level);
			
			levelDown.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					GameStartConfig.levelTryDown();
					selectLevel.setText("Level " + GameStartConfig.level);
				}
			});
			
			ImageView levelUp = (ImageView)acty.findViewById(R.id.levelUp);
			levelUp.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					GameStartConfig.levelTryUp();
					selectLevel.setText("Level " + GameStartConfig.level);
				}
			});
		}
		{
			final TextView selectMap = (TextView)acty.findViewById(R.id.selectMap);
			ImageView mapDown = (ImageView)acty.findViewById(R.id.mapDown);
			selectMap.setText(MapsDao.getMapNameBy(GameStartConfig.mapId));
			
			mapDown.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					GameStartConfig.mapTryDown();
					selectMap.setText(MapsDao.getMapNameBy(GameStartConfig.mapId));
				}
			});
			
			ImageView mapUp = (ImageView)acty.findViewById(R.id.mapUp);
			mapUp.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					GameStartConfig.mapTryUp();
					selectMap.setText(MapsDao.getMapNameBy(GameStartConfig.mapId));
				}
			});
		}
		{
			final CheckBox checkBox = (CheckBox)acty.findViewById(R.id.soundEnable);
			checkBox.setChecked(GameStartConfig.soundEnable);
			checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){

				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					GameStartConfig.soundEnable = isChecked;
				}});

		}
		{
			Button goBackBtn = (Button)acty.findViewById(R.id.goBack);
			goBackBtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					acty.setContentView(R.layout.main);
				}
			});
		}
		{
			Button startBtn = (Button)acty.findViewById(R.id.start);
			startBtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					BattleEngine.init();
					acty.setContentView(new ViewPort(acty));
				}
			});
		}
	}

}
